"""
抽奖
"""
from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session
from schemas import Lottery, LotteryCreate, LotteryAdjust, LotteryDelete

from app.dependencies import get_db
from sql_app.crud import crud_lottery
from utils import await_task, resp_200, resp_detail_200

router = APIRouter(
    prefix="/lottery",
    tags=["lottery"],
    responses={404: {"description": "Not found"}}
)


@router.get("/get_list")
async def get_list(
        accesstoken: str = Query(..., example="TOKEN3590"),
        pageidx: int = Query(..., example = 1),
        pagesize: int = Query(..., example = 20), keyword: str = None,
        db: Session = Depends(get_db)):
    total = await await_task(crud_lottery.get_count, db)
    data = await await_task(
        crud_lottery.get_a_batch, db, (pageidx-1)*pagesize, pagesize, keyword
    )
    print(Lottery.from_orm(data[0]))
    return resp_200(total=total, data=[Lottery.from_orm(i) for i in data])


@router.post("/add")
async def add(
    lottery: LotteryCreate, db: Session=Depends(get_db)
):
    await await_task(crud_lottery.create, db, lottery)
    return resp_200()


@router.post("/adjust")
async def adjust(
        lottery: LotteryAdjust, db: Session = Depends(get_db)):
    await await_task(crud_lottery.adjust, db, lottery)
    return resp_200()


@router.get("/get_info")
async def get_info(
        accesstoken: str=Query(..., example="TOKEN3590"),
        id: int = Query(..., example=1),
        db: Session = Depends(get_db)
):
    data = await await_task(
        crud_lottery.get_detail, db, id)

    return resp_detail_200(data=Lottery.from_orm(data))


@router.post("/delete")
async def delete(
        lottery: LotteryDelete, db: Session = Depends(get_db)):
    await await_task(crud_lottery.delete, db, lottery)
    return resp_200()


@router.get("/get_award_list")
async def get_award_list():
    pass


@router.get("/get_award_goods_list")
async def get_award_goods_list():
    pass


@router.post("/add_award")
async def add_award():
    pass


@router.post("/adjust_award")
async def adjust_award():
    pass


@router.post("/delete_award")
async def delete_award():
    pass


@router.post("/delete_award_goods")
async def delete_award_goods():
    pass


@router.post("/add_award_goods")
async def delete_award_goods():
    pass


@router.post("/adjust_award_goods")
async def delete_award_goods():
    pass


